/*
 * Created on Feb 23, 2004
 *
 * Author: Sandeep Prakash. Modified by Klarinda
 * Project: Sucxentv2 (using leaf nodes only)
 */
package dbsucxentW.storageW.entitiesW;

import dbsucxentW.storageW.loadersW.Store;
import java.util.Hashtable;
import java.util.Set;
import java.util.Map.Entry;


/**
 * Used to manage the Path and PathId
 */
public abstract class PathCollection {
    protected Hashtable<String, Integer> _paths;

    public Set<Entry<String, Integer>> getPaths() {
        return this._paths.entrySet();
    }

    private Store store;

    protected int _maxId = 0;
    protected int _updateId = 0;

    public PathCollection(Store store) {
        _paths = new Hashtable<String, Integer>();
        this.store = store;
    }

    /**
     * Retrieve the path ID corresponding to the input path.
     * If the path ID does not exist, create a new unique one
     * @param path      Input path
     * @return          Unique path ID
     */
    public int getPathId(String path) {

        if (_paths.containsKey(path)) {
            return ((Integer) _paths.get(path)).intValue();
        } else {
            _maxId++;
            _paths.put(path, new Integer(_maxId));
            store.storePath(_maxId, path);
            return _maxId;
        }
    }
}
